package cn.jboa.action;

import cn.jboa.common.Constants;
import cn.jboa.entity.SysEmployee;
import cn.jboa.exception.JboaException;
import cn.jboa.service.EmployeeService;
import cn.jboa.util.MD5;
import com.opensymphony.xwork2.ActionSupport;
import org.omg.PortableInterceptor.INACTIVE;

public class EmployeeAction extends BaseAction {

    private EmployeeService empService;
    private SysEmployee employee;
    private String msg;
    private SysEmployee manager;
    private  String random;
    public String login(){
        Object sessionRandom  = this.getSession().get("random");
        if (random == null || !random.equals(sessionRandom)) {
            this.addActionError(this.getText("验证码错误"));
            return INPUT;
        }
        try{
            employee=empService.login(employee);
            manager=empService.getManager(employee);
            this.getSession().put(Constants.AUTH_EMPLOYEE,employee);
            this.getSession().put(Constants.AUTH_EMPLOYEE_MANAGER,manager);
            this.getSession().put(Constants.EMPLOYEE_POSITION,employee.getSysPosition().getNameCn());
        }catch (JboaException e){
            this.addActionError(this.getText("无效的用户名或密码"));
            msg=this.getText("无效的用户名或密码");
            e.printStackTrace();
        }
        if(msg!=null)
            return INPUT;
        return SUCCESS;
    }
    public SysEmployee getEmployee() {
        return employee;
    }

    public void setEmployee(SysEmployee employee) {
        this.employee = employee;
    }

    public EmployeeService getEmpService() {
        return empService;
    }

    public void setEmpService(EmployeeService empService) {
        this.empService = empService;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public SysEmployee getManager() {
        return manager;
    }

    public void setManager(SysEmployee manager) {
        this.manager = manager;
    }

    public String getRandom() {
        return random;
    }

    public void setRandom(String random) {
        this.random = random;
    }
}
